//
//  FourthViewController.m
//  uplife
//
//  Created by ZhangCheng on 2018/12/24.
//  Copyright © 2018年 ZhangCheng. All rights reserved.
//

#import "FourthViewController.h"
#import "YQYPiecewiseView.h"
#import "GRXXTableViewController.h"
#import "TBZXRootViewController.h"
#import "TBZXDetailViewController.h"
#import "OrderDetailTableViewController.h"
@interface FourthViewController ()<YQYPiecewiseViewDelegate>
@property(nonatomic,weak)IBOutlet UIView *segmentSuperView;

@property(nonatomic,weak)IBOutlet UIView *GRXXView;
@property(nonatomic,weak)IBOutlet UIView *TBZXView;
@end

@implementation FourthViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self.segmentSuperView setFrame:CGRectMake(0, 0, self.view.frame.size.width - 32.0f, 44.0f)];
    [self creatSegument];
    for (UIViewController *vc in self.childViewControllers) {
        if ([vc isKindOfClass:[GRXXTableViewController class]]) {
            GRXXTableViewController *grxxVC = (GRXXTableViewController *)vc;
            grxxVC.fourthViewController = self;
        }else if ([vc isKindOfClass:[TBZXRootViewController class]]) {
            TBZXRootViewController *grxxVC = (TBZXRootViewController *)vc;
            grxxVC.fourthViewController = self;
        }
    }
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
}

- (void)creatSegument
{
    NSArray *arr = [NSArray arrayWithObjects:@"个人信息",@"特别专享", nil];
    YQYPiecewiseView *piecew = [[YQYPiecewiseView alloc] initWithFrame:CGRectMake(0, 0, self.segmentSuperView.frame.size.width, self.segmentSuperView.frame.size.height)];
    piecew.type = PiecewiseInterfaceTypeMobileLin;
    piecew.delegate = self;
    piecew.linColor = [UIColor colorWithRed:203/255.0 green:172/255.0 blue:116/255.0 alpha:1.0];
    piecew.textNormalColor = [UIColor colorWithRed:220/255.0 green:220/255.0 blue:220/255.0 alpha:1.0];
    //    piecew.textNormalColor = [UIColor whiteColor];
    piecew.textSeletedColor = [UIColor colorWithRed:203/255.0 green:172/255.0 blue:116/255.0 alpha:1.0];
    piecew.textFont = [UIFont systemFontOfSize:16];
    [piecew loadTitleArray:arr];
    [self.segmentSuperView addSubview:piecew];
}

-(void)piecewiseView:(YQYPiecewiseView *)piecewiseView index:(NSInteger)index
{
    switch (index) {
        case 0:
        {
            self.GRXXView.hidden = NO;
            self.TBZXView.hidden = YES;
        }
            break;
        case 1:
        {
            self.GRXXView.hidden = YES;
            self.TBZXView.hidden = NO;
        }
        default:
            break;
    }
}

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    if ([segue.identifier isEqualToString:@"toDetail"]) {
        TBZXDetailViewController *vc = segue.destinationViewController;
        vc.dataId = sender;
    }else if ([segue.identifier isEqualToString:@"toBuy"]){
        OrderDetailTableViewController *vc = segue.destinationViewController;
        vc.dataDic = sender;
    }
}

@end
